import MessageBox from "./MessageBox";
import {EventEmitter} from "events"
import message from "./Message";
import Group from "./Group";
import MessageBoxForSingleUser from "./MessageBoxForSingleUser";
import {USER} from "../config/config";

class MessageBoxForGroup extends MessageBox {

    constructor(emailOwner: string, userId: string) {
        super(emailOwner, userId);
    }

    public async insertNewMessage(messageType:string,senderId:string,context:string,senderName:string,originSender:string) {
        await super.insertNewMessage(messageType, senderId, context,senderName,originSender);

        let groupMember = await Group.GetGroupMember(this._userId);
        for (let member of groupMember) {
            if (member != originSender) {
                let messageBox = new MessageBoxForSingleUser(USER, member);
                await messageBox.insertNewMessage(messageType, senderId, context,senderName,originSender);
            }
        }
    }
}

export default MessageBoxForGroup;